package com.sikaryofficial.common.core.annotation;

import cn.hutool.core.text.CharSequenceUtil;
import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.sikaryofficial.common.core.utils.sql.SqlUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

/**
 * @author : qinjinyuan
 * @desc : 自定义转义 反序列化
 * @date : 2023/12/14 9:53
 */
@Slf4j
@JsonComponent
public class SqlEscapeDeserializer extends JsonDeserializer<String> {
    /**
     * @param jsonParser
     * @param deserializationContext
     * @return
     * @throws IOException
     * @throws JacksonException
     */
    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        if(CharSequenceUtil.isBlank(jsonParser.getText())){
            return null;
        }
        return SqlUtil.escapeKeyword(jsonParser.getText());
    }
}
